package main

import (
	"golang.org/x/net/context"

	rpc "google.golang.org/grpc"
	"log"
	"region/grpc"
	"time"
)

func main() {
	conn, err := rpc.Dial(":50051", rpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}

	defer conn.Close()
	c := grpc.NewGreeterClient(conn)

	// ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	// defer cancel()
	time.Sleep(3 * time.Second)
	ctx := context.Background()
	r, err := c.SayHello(ctx, &grpc.HelloRequest{Name: "world"})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Printf("Greeting:%s", r.Message)

	c2 := grpc.NewGreetClient(conn)
	r2, err := c2.SayHello(ctx, &grpc.HelloRequest{Name: "world2"})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Printf("Greeting:%s", r2.Message)
}
